import os
from dotenv import load_dotenv

load_dotenv()

class DatabaseConfig:
    """数据库配置"""
    # SQL Server 配置
    SERVER = os.getenv("DB_SERVER", "101.201.68.169:1433")
    DATABASE = os.getenv("DB_NAME", "4GSignalCollection")
    USERNAME = os.getenv("DB_USER", "sa")
    PASSWORD = os.getenv("DB_PASSWORD", "sqlserver2008r2**")
    DRIVER = os.getenv("DB_DRIVER", "ODBC Driver 17 for SQL Server")
    
    
    @classmethod
    def get_mssql_config(cls):
        """获取MSSQL连接配置"""
        # 解析服务器和端口
        if ':' in cls.SERVER:
            host, port = cls.SERVER.split(':')
        else:
            host = cls.SERVER
            port = '1433'
        
        return {
            'host': host,
            'port': int(port),
            'user': cls.USERNAME,
            'pwd': cls.PASSWORD,
            'db': cls.DATABASE
        }

class AppConfig:
    """应用配置"""
    DEBUG = os.getenv("DEBUG", "False").lower() == "true"
    HOST = os.getenv("HOST", "0.0.0.0")
    PORT = int(os.getenv("PORT", "8886"))
    CORS_ORIGINS = os.getenv("CORS_ORIGINS", "*").split(",")